#ifndef OBJECTACTIONS_H
#define OBJECTACTIONS_H

#include <QStringList>

class QXmlStreamReader;
class QXmlStreamWriter;
class RosterUnit;

class ObjectAction {
    // Abstract class
public:
    enum ActionType {
        AddItems = 0,
        AddUnit,
        ModifyCell,
        ChangeAllowedItems,
        ChangeGlobalTexts,
        ChangeItemLimits,
        ChangeLockedOptions,
        ChangeShownOptions,
        CustomScript
    };

    virtual ~ObjectAction();

    virtual void doAction(RosterUnit *unit) = 0;
    virtual void undoAction(RosterUnit *unit) = 0;

    virtual ActionType type() const = 0;

    virtual void readFromFile(QXmlStreamReader *reader) = 0;
    virtual void writeToFile(QXmlStreamWriter *writer) = 0;

    // Factory. User handle deletion of ObjectAction*
    static ObjectAction* createAction(ActionType type);
};

class GlobalTextAction : public ObjectAction {
public:
    GlobalTextAction();
    virtual void doAction(RosterUnit *unit);
    virtual void undoAction(RosterUnit *unit);
    virtual ActionType type() const;
    virtual void readFromFile(QXmlStreamReader *reader);
    virtual void writeToFile(QXmlStreamWriter *writer);

private:

};

class AddItemAction : public ObjectAction {
public:
    AddItemAction();
    AddItemAction(const QStringList &items);
    virtual void doAction(RosterUnit *unit);
    virtual void undoAction(RosterUnit *unit);
    virtual ActionType type() const;
    virtual void readFromFile(QXmlStreamReader *reader);
    virtual void writeToFile(QXmlStreamWriter *writer);

    QStringList getItems() const;

private:
    QStringList _items;
};

class AddUnitAction : public ObjectAction {
public:
    AddUnitAction();
    AddUnitAction(const QString& unitKey, bool replacesModel);
    virtual void doAction(RosterUnit *unit);
    virtual void undoAction(RosterUnit *unit);
    virtual ActionType type() const;
    virtual void readFromFile(QXmlStreamReader *reader);
    virtual void writeToFile(QXmlStreamWriter *writer);

    QString getUnitKey() const;
    bool replacesModel() const;

private:
    QString _unitKey;
    bool _replacesModel;
};

// \TODO: More classes pending


/*class AllowedItemAction : public ObjectAction {
public:
    virtual void doAction(RosterUnit *unit);
    virtual void undoAction(RosterUnit *unit);
    virtual ActionType type() const;
    virtual void readFromFile(QXmlStreamReader *reader);
    virtual void writeToFile(QXmlStreamWriter *writer);

private:

};*/

class ModifyCellAction : public ObjectAction {
public:
    ModifyCellAction();
    ModifyCellAction(const QString& cell, const QString& value, bool onlyAppend);

    virtual void doAction(RosterUnit *unit);
    virtual void undoAction(RosterUnit *unit);
    virtual ActionType type() const;
    virtual void readFromFile(QXmlStreamReader *reader);
    virtual void writeToFile(QXmlStreamWriter *writer);

    QString getCellKey() const;
    QString getValue() const;
    bool getOnlyAppend() const;

private:
    QString _cell, _value;
    bool _onlyAppend;
};

#endif // OBJECTACTIONS_H
